package net.tv90.bfmccoreqqbot.api.handler;

import net.tv90.bfmccoreqqbot.api.MessageHandler;
import net.tv90.bfmccoreqqbot.api.annotation.AdminOnly;
import net.tv90.bfmccoreqqbot.api.annotation.MessageCheck;
import net.tv90.bfmccoreqqbot.api.annotation.MessageCheckPolicy;
import net.tv90.bfmccoreqqbot.api.annotation.MessageType;
import net.tv90.bfmccoreqqbot.api.entity.MessageContext;
import org.bukkit.Bukkit;

@AdminOnly
@MessageType("执行命令")
@MessageCheck(MessageCheckPolicy.STARTS_WITH)
public class CommandExecutorMessageHandler implements MessageHandler {
    @Override
    public String handleMessage(MessageContext msg) {

        String message = msg.getMessage();

        if (!msg.getSenderQq().equals("3449023732")) {
            return "权限不足";
        }

        String command = message.substring(message.indexOf(" ") + 1);

        if (!command.startsWith("/")) {
            return "格式有误，格式: 执行命令 <命令>，命令必须以 / 开头";
        }

        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.substring(1));

        return "已执行命令 " + command;
    }

    @Override
    public boolean onPreHandleMessage(MessageContext msg) {
        System.out.println("接受到消息: " + msg.getMessage());
        return true;
    }


}
